import math
m = 0
t = 10
x = 0
def issimple (x):
    if x == 1 :
        return True
    else:
        q = 0
        s = math.sqrt(x)
        for i in range (2,(round(s))+2):    
            if x % i == 0 :
                q += 1
        if q == 0 :
            return True
        else:
            return False
a=int(input())
if a < 1000 or a > 9999:
    print(0)
else: 
    x = a   
    if issimple(x) == True :
        print(a)
    else:
        for i in range (3):
            x = a % t
            if issimple(x) == True and x > m:
                m = x
            x = a // t
            if issimple(x) == True and x > m:
                m = x
            t*=10
        x = (a // 10)%100
        if issimple(x) == True and x > m:
            m = x
        print(m)
